//
//  ZQTabBarController.m
//  BuDeJie
//
//  Created by zuqiu on 17/10/27.
//  Copyright © 2017年 zuqiu. All rights reserved.
//
#import "ZQPublishPage.h"
#import "ZQNewPage.h"
#import "ZQEssencePage.h"
#import "ZQFriendTrendPage.h"
#import "ZQMeTableViewPage.h"
#import "ZQTabBarController.h"
#import "UIImage+Image.h"
#import "ZQTabBar.h"

@interface ZQTabBarController ()

@end

@implementation ZQTabBarController
+ (void)load
{
    //  appearance在控件显示之前有用
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    // 文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:attrs forState:UIControlStateSelected];
    
    // 文字字体只有设置正常状态下才有效果
    NSMutableDictionary *attrFot = [NSMutableDictionary dictionary];
    attrFot[NSFontAttributeName] = [UIFont systemFontOfSize:13 ];
    [item setTitleTextAttributes:attrFot forState:UIControlStateNormal];
    
}

//+ (void)initialize
//{
//    if (self == [ZQTabBarController class]) {
//        
//    }
//}
#pragma mark - 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAllChildViewControllers];
    [self setAllChildTitleButton];
    [self settabbarView];
}

#pragma mark - set自定义的tabbar
- (void)settabbarView
{
    ZQTabBar *tabBarNew = [[ZQTabBar alloc]init];
 
    [self setValue:tabBarNew forKeyPath:@"tabBar"];
}

#pragma mark - 添加所有的子控制器
- (void)setAllChildViewControllers
{
    // 精华
    ZQEssencePage *essencePage = [ZQEssencePage new];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:essencePage];
    [self addChildViewController:nav1];
    
    // 新帖
    ZQNewPage *newPage = [ZQNewPage new];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:newPage];
    [self addChildViewController:nav2];
    
//    // 发布
//    ZQPublishPage *publishPage = [ZQPublishPage new];
//    [self addChildViewController:publishPage];
    
    // 关注
    ZQFriendTrendPage *friendTrendPage = [ZQFriendTrendPage new];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:friendTrendPage];
    [self addChildViewController:nav3];
    
    // 我
    ZQMeTableViewPage *mePage = [ZQMeTableViewPage new];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:mePage];
    [self addChildViewController:nav4];
}

- (void)setAllChildTitleButton
{
    UINavigationController *nav1 = self.childViewControllers[0];
    nav1.tabBarItem.title  = @"精华";
    nav1.tabBarItem.image= [UIImage imageNamed:@"tabBar_essence_icon"];
    nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_essence_click_icon"];
    
    
    UINavigationController *nav2 = self.childViewControllers[1];
    nav2.tabBarItem.title  = @"新帖";
    nav2.tabBarItem.image= [UIImage imageNamed:@"tabBar_new_icon"];
    nav2.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    
    
//    ZQPublishPage *publishPage = self.childViewControllers[2];
//    publishPage.tabBarItem.image= [UIImage imageOriginalWithName:@"tabBar_publish_icon"];
//    publishPage.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_publish_click_icon"];
//    publishPage.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    
      UINavigationController *nav3 = self.childViewControllers[2];
    nav3.tabBarItem.title  = @"关注";
    nav3.tabBarItem.image= [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav3.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_friendTrends_click_icon"];
    UINavigationController *nav4 = self.childViewControllers[3];

    nav4.tabBarItem.title  = @"我";
    nav4.tabBarItem.image= [UIImage imageNamed:@"tabBar_me_icon"];
    nav4.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_me_click_icon"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
